using System;
using System.Windows.Forms;
using System.Reflection;

namespace Tourreau.Gilles.FaxDotNet.Demo
{
    internal static class FaxMessageBox
    {
        public static void Error(string message, params object[] parameters)
        {
            string title;

            if (Form.ActiveForm == null)
            {
                title = GetProductName();
            }
            else
            {
                title = Form.ActiveForm.Text;
            }

            MessageBox.Show(string.Format(message, parameters), title, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        
        private static string GetProductName()
        {
            AssemblyTitleAttribute attribute;

            attribute = (AssemblyTitleAttribute)Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0];

            return attribute.Title;
        }
    }
}
